#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 6, M = 1e6 + 6;
int t, n, a[N];
int f[N], k[M];
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    scanf("%d", &t);
    for(int i = 1; i <= t; ++ i){
        memset(f, 0, sizeof f);
        memset(k, 0, sizeof k);
        scanf("%d", &n);
        for(int i = 1; i <= n; ++ i){
            scanf("%d", &a[i]);
            if(k[a[i]] != 0){
                if(k[a[i]] - i <= 1) f[i] = f[i-1] + a[i];
                else f[i] = max(f[i-1], f[k[a[i]]-1] + a[i]);
            }
            else f[i] = f[i-1];
            k[a[i]] = i;

        }
        printf("%d\n", f[n]);
    }
    return 0;
}
